home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / src / text.c < prev    next >
C/C++ Source or Header  |  1997-08-17  |  5KB  |  296 lines

  1. #include <stdio.h>
  2.  
  3. #if defined(PC) || defined(AZTEC_C)  || defined(AMIGA)
  4. #include <string.h>
  5. #else
  6. #include <strings.h>
  7. #endif
  8. #include "vogl.h"
  9.  
  10. /* ---------------------------------------------------------------------
  11.  * Local Variables:
  12.  */
  13. static    float    c_x, c_y, c_z;    /* Current character position */
  14.  
  15. /* ---------------------------------------------------------------------
  16.  * Prototypes:
  17.  */
  18. #ifdef __PROTOTYPE__
  19. static float getcharwidth(void);                       /* text.c          */
  20. #else    /* __PROTOTYPE__ */
  21. static float getcharwidth();                           /* text.c          */
  22. #endif    /* __PROTOTYPE__ */
  23.  
  24. /* ---------------------------------------------------------------------
  25.  * Source Code:
  26.  */
  27.  
  28. /*
  29.  * font
  30.  *     assigns a font.
  31.  */
  32. void font(short id)
  33. {
  34. Token    *tok;
  35.  
  36. if (!vdevice.initialised)
  37. verror("font: vogl not initialised");
  38.  
  39. if (id < 0 || id >= vdevice.maxfontnum)
  40. verror("font: font number is out of range");
  41.  
  42. if (vdevice.inobject) {
  43.     tok = newtokens(2);
  44.     tok[0].i = FONT;
  45.     tok[1].i = id;
  46.     return;
  47.     }
  48.  
  49. if (id == 1) {
  50.     if (!(*vdevice.dev.Vfont)(vdevice.dev.large)) 
  51.     verror("font: unable to open large font");
  52.     }
  53. else if (id == 0) {
  54.     if (!(*vdevice.dev.Vfont)(vdevice.dev.small))
  55.     verror("font: unable to open small font");
  56.     }
  57.  
  58. vdevice.attr->a.fontnum = id;
  59. }
  60.  
  61. /* ------------------------------------------------------------------------ */
  62.  
  63. /*
  64.  * getcharwidth
  65.  *
  66.  *     Gets the width of one char on world coords.
  67.  */
  68. static float getcharwidth(void)
  69. {
  70. float           a, b, c, d;
  71.  
  72. VtoWxy(vdevice.hwidth, vdevice.hheight, &c, &d);
  73. VtoWxy(0.0, 0.0, &a, &b);
  74. c -= a;
  75. return(c);
  76. }
  77.  
  78. /* ------------------------------------------------------------------------ */
  79.  
  80. /*
  81.  * charstr
  82.  *
  83.  * Draw a string from the current character position.
  84.  *
  85.  */
  86. void charstr(char *str)
  87. {
  88. float    cx, cy, cz;
  89. char    c;
  90. Token    *tok;
  91. int    oldclipoff = vdevice.clipoff;
  92. int    sl = strlen(str);
  93.  
  94. if(!vdevice.initialised) 
  95. verror("charstr: vogl not initialized");
  96.  
  97. if (vdevice.inobject) {
  98.     tok = newtokens(2 + strlen(str) / sizeof(Token));
  99.  
  100.     tok[0].i = DRAWSTR;
  101.     strcpy((char *)&tok[1], str);
  102.  
  103.     return;
  104.     }
  105.  
  106. cx = vdevice.cpW[V_X];
  107. cy = vdevice.cpW[V_Y];
  108. cz = vdevice.cpW[V_Z];
  109.  
  110. vdevice.clipoff = 1;    /* Forces update of device coords */
  111. move(c_x, c_y, c_z);    /* Updates device coords      */
  112.  
  113. /*   If not clipping then simply display text and return  */
  114.  
  115. if (oldclipoff) {
  116.     (*vdevice.dev.Vstring)(str);
  117.     }
  118. else { /* Check if string is within viewport */
  119.     int    left_s = vdevice.cpVx;
  120.     int    bottom_s = vdevice.cpVy - (int)vdevice.hheight;
  121.     int    top_s = bottom_s + (int)vdevice.hheight;
  122.     int    right_s = left_s + (int)((sl + 1) * vdevice.hwidth);
  123.  
  124.     if (left_s > vdevice.minVx &&
  125.         bottom_s < vdevice.maxVy &&
  126.         top_s > vdevice.minVy &&
  127.         right_s < vdevice.maxVx) {
  128.         (*vdevice.dev.Vstring)(str);
  129.         }
  130.     else {
  131.         while (c = *str++) {
  132.             if (vdevice.cpVx > vdevice.minVx &&
  133.                 vdevice.cpVx < vdevice.maxVx - (int)vdevice.hwidth) {
  134.                 (*vdevice.dev.Vchar)(c);
  135.                 }
  136.             vdevice.cpVx += vdevice.hwidth;
  137.             }
  138.         }
  139.     }
  140.  
  141. c_x += getcharwidth() * sl;
  142.  
  143. move(cx, cy, cz);
  144. vdevice.clipoff = oldclipoff;
  145. }
  146.  
  147. /* ------------------------------------------------------------------------ */
  148.  
  149. /*
  150.  * cmov
  151.  *
  152.  *    Sets the current character position.
  153.  */
  154. void cmov(
  155.   float x,
  156.   float y,
  157.   float z)
  158. {
  159. Token    *tok;
  160.  
  161. if (vdevice.inobject) {
  162.     tok = newtokens(4);
  163.  
  164.     tok[0].i = CMOV;
  165.     tok[1].f = x;
  166.     tok[2].f = y;
  167.     tok[3].f = z;
  168.  
  169.     return;
  170.     }
  171.  
  172. c_x = x;
  173. c_y = y;
  174. c_z = z;
  175. }
  176.  
  177. /* ------------------------------------------------------------------------ */
  178.  
  179.  
  180. /*
  181.  * cmov2
  182.  *
  183.  *    Sets the current character position. Ignores the Z coord.
  184.  *    
  185.  *
  186.  */
  187. void cmov2(
  188.   float x,
  189.   float y)
  190. {
  191. c_x = x;
  192. c_y = y;
  193. c_z = 0.0;
  194. }
  195.  
  196. /* ------------------------------------------------------------------------ */
  197.  
  198. /*
  199.  * cmovi
  200.  *
  201.  *    Same as cmov but with integer arguments....
  202.  */
  203. void cmovi(
  204.   Icoord x,
  205.   Icoord y,
  206.   Icoord z)
  207. {
  208. c_x = (Coord)x;
  209. c_y = (Coord)y;
  210. c_z = (Coord)z;
  211. }
  212.  
  213. /* ------------------------------------------------------------------------ */
  214.  
  215. /*
  216.  * cmovs
  217.  *
  218.  *    Same as cmov but with short integer arguments....
  219.  */
  220. void cmovs(
  221.   Scoord x,
  222.   Scoord y,
  223.   Scoord z)
  224. {
  225. c_x = (Coord)x;
  226. c_y = (Coord)y;
  227. c_z = (Coord)z;
  228. }
  229.  
  230. /* ------------------------------------------------------------------------ */
  231.  
  232. /*
  233.  * cmov2i
  234.  *
  235.  *    Same as cmov2 but with integer arguments....
  236.  */
  237. void cmov2i(
  238.   Icoord x,
  239.   Icoord y)
  240. {
  241. c_x = (Coord)x;
  242. c_y = (Coord)y;
  243. c_z = 0.0;
  244. }
  245.  
  246. /* ------------------------------------------------------------------------ */
  247.  
  248. /*
  249.  * cmov2s
  250.  *
  251.  *    Same as cmov but with short integer arguments....
  252.  */
  253. void cmov2s(
  254.   Scoord x,
  255.   Scoord y)
  256. {
  257. c_x = (Coord)x;
  258. c_y = (Coord)y;
  259. c_z = 0.0;
  260. }
  261.  
  262. /* ------------------------------------------------------------------------ */
  263.  
  264. /*
  265.  * getwidth
  266.  *
  267.  * Return the maximum Width of the current font.
  268.  *
  269.  */
  270. long getwidth(void)
  271. {
  272. if (!vdevice.initialised)
  273. verror("getwidth: vogl not initialised");
  274.  
  275.  
  276. return((long)vdevice.hwidth);
  277. }
  278.  
  279. /* ------------------------------------------------------------------------ */
  280.  
  281. /* 
  282.  * getheight
  283.  *
  284.  * Return the maximum Height of the current font
  285.  */
  286. long getheight(void)
  287. {
  288. if (!vdevice.initialised)
  289. verror("getheight: vogl not initialized");
  290.  
  291. return((long)vdevice.hheight);
  292. }
  293.  
  294. /* ------------------------------------------------------------------------ */
  295.  
  296.